package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.PictureEntity;
import com.shishuo.cms.entity.VideoEntity;
import com.shishuo.cms.plugin.TagPlugin;
import com.shishuo.cms.service.PictureService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Service
public class PictureTag extends BaseTagPlugin {

	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		long id = Long.parseLong(params.get("id").toString());
		int page = Integer.parseInt(params.get("p").toString());
		try {
			PictureEntity pictureEntity = pictureService.getById(id);
			if (null != pictureEntity) {
				env.setVariable("tag_picture", BEANS_WRAPPER.wrap(pictureEntity));
			}
			body.render(env.getOut());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
